import java.util.Calendar;
import java.util.ArrayList;


/*
//Cruise Class contains 
	-a collection of ports
	-a collection of trips (Start date + end date)
	-a collection of cabins (Family || Single)
*
*
*/


//We use the Traveling constructor to ensure a valid cruise name
//All other members and functions are specific to the cruise object and do not apply to the flight class
public class Cruise extends Traveling{

	
	//Data Members
	/*Cruise_Line Name
	 *Array of Ports
	 *ArrayList of trips
	 *Cabins
	 * 
	 * 
	 * 
	*/

	//ArrayList<Port> ports;
	Port[] ports;
	ArrayList<Trip> trips;
	
	int numSingleCabinsPossible;
	int numFamilyCabinsPossible;
	
	private Cruiseline owner;
	
	//A cruise object is created with a collection of valid ports plus an Cruise Company name. 
	//A 6 character name is also given to the cruise. 
	public Cruise(Cruiseline ownerArg, Port[] ctr_ports,  String idArg, int numFamCabins, int numSingleCabins) throws ManagementException{
		
		super (idArg);
		ports = ctr_ports;
		numSingleCabinsPossible = numSingleCabins;
		numFamilyCabinsPossible = numFamCabins;
		if (ownerArg == null) {
			throw new ManagementException ("You are trying to create " + this.toString() + " with no cruiseline.");
		}
		
		owner = ownerArg;
	
	}

	public void addTrip(Calendar beginDate, Calendar endDate) throws ManagementException{

		Trip tempTrip = new Trip (beginDate, endDate, trips.size(), numSingleCabinsPossible, numFamilyCabinsPossible );
		trips.add(tempTrip);

	}


	public ArrayList< Trip > getTrips(){

		return trips;

	}

	public boolean hasTrips(){

		return !(trips.isEmpty());


	}


	//Returns true if cabin booking was successful. 
	//Will return false if there are no vacancies for a given trip and a desired cabin. 
	//CabinType 1 == single
	//CabinType 2 == family
	public boolean bookTrip(int tripID, int cabinType){


		//The trip ID must be contained in the trips array list
		if (trips.size() <= tripID) return false;

		return trips.get(tripID).reserveCabin(cabinType);


	}

	public String toString(){
		/*
		 * Cruise_Company
		 * 	Cruise Name
		 * 		Visits
		 * 			-Port A
		 * 			-Port B
		 * 			-etc...
		 * 		For the following dates:
		 * 			-Trip A
		 * 			-Trip B
		 */

		String returnString = owner.toString() + "\n \t" + id + "\n\t\tVists the following Ports \n";
		for (int i=0; i<ports.length; i++){

			returnString += "\t\t\t" + ports[i].toString() + "\n";
		}

		returnString += "\t\tFor the following dates: \n";

		for (int i=0; i<trips.size(); i++){
			returnString += "\t\t\t" + trips.get(i).toString() + "\n";
		}


		return returnString;

	}
}
